package com.yyairmarkyy.arctool.window;

import android.content.Context;
import android.graphics.PixelFormat;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;

import com.yyairmarkyy.arctool.R;
import com.yyairmarkyy.arctool.item.AiyouArcMenuItem;


/**
 * Created by aiyou on 2017/10/26.
 */

public class MyWindowParamsHelper extends ArcToolWindowParamsHelper {


    public static int LEVEL_ONE_TOP_RADIUS = 724 ;
    public static int LEVEL_TWO_TOP_RADIUS = 844;

    public static int CENTER_TOPRADIUS = 75;
    public static int CENTER_ICON_X = 18;
    public static int CENTER_ICON_Y = 18;
    public static int CENTER_ICON_WIDTH = 50;

    public static int TOOL_ITEM_RADIUS = 640;
    public static int GAME_ITEM_RADIUS = 686;
    public static int COLOR_ITEM_RADIUS = 832;

    public static int FADE_FRIST_RADIUS = 454;
    public static int FADE_WITDH = 10;
    public static int FADE_SECOND_RADIUS = 734 ;

    public static int MENU_TOP_RADIUS = 440;
    public static int MENU_ITEM_RADIUS = 394;



    private int[] menuIconResid = {R.mipmap.menu_game_icon, R.mipmap.menu_tool_icon,R.mipmap.menu_mine_icon};
    private int[] menuSelectedIconResid = {R.mipmap.menu_game_selected_icon,R.mipmap.menu_tool_selected_icon,R.mipmap.menu_mine_selected_icon};


    public ImageView[] menuImageViews;




    public WindowManager.LayoutParams makeWindowParams(int type){
//        WindowManager.LayoutParams.TYPE_APPLICATION
//                |WindowManager.LayoutParams.FLAG_DIM_BEHIND|WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
        WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(type);
        layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
        layoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
        layoutParams.format = PixelFormat.RGBA_8888;
        return layoutParams;
    }

    @Override
    protected AiyouArcMenuItem createMenuItem(Context context) {
        menuImageViews = new ImageView[3];
        ImageView friIv = new ImageView(context);
        friIv.setImageResource(R.mipmap.menu_game_selected_icon);
        friIv.setTag(0);
        friIv.setOnClickListener(new InternalMenuOnClickListener());
        menuImageViews[0] = friIv;

        ImageView secIv = new ImageView(context);
        secIv.setImageResource(R.mipmap.menu_tool_icon);
        secIv.setTag(1);
        secIv.setOnClickListener(new InternalMenuOnClickListener());
        menuImageViews[1] = secIv;

        ImageView thirIv = new ImageView(context);
        thirIv.setImageResource(R.mipmap.menu_mine_icon);
        thirIv.setTag(2);
        thirIv.setOnClickListener(new InternalMenuOnClickListener());
        menuImageViews[2] = thirIv;


        aiyouArcMenuItem = new AiyouArcMenuItem();
        aiyouArcMenuItem.setPerViewWidth(163);
        aiyouArcMenuItem.setPerViewHeight(163);
        aiyouArcMenuItem.setTopRadius(MENU_TOP_RADIUS);
        aiyouArcMenuItem.setItemRadius(MENU_ITEM_RADIUS);
        aiyouArcMenuItem.setPerViews(menuImageViews);
        aiyouArcMenuItem.setPerViewRadius(new int[]{20, 45, 68});

        return aiyouArcMenuItem;
    }





    private class InternalMenuOnClickListener implements View.OnClickListener{

        @Override
        public void onClick(View v) {
            switch ((int)v.getTag()){
                case 0:
                    if (menuOnclickLisitener != null)
                        menuOnclickLisitener.menuOnClick(0);
                    break;
                case 1:
                    if (menuOnclickLisitener != null)
                        menuOnclickLisitener.menuOnClick(1);
                    break;
                case 2:
                    if (menuOnclickLisitener != null)
                        menuOnclickLisitener.menuOnClick(2);
                    break;
            }
            changeMenuIconForClick((int)v.getTag());
        }
    }


    /**
     * 根据点击改变菜单图标
     * @param clickIndex
     */
    private void changeMenuIconForClick(int clickIndex){
        for (int i = 0; i<menuImageViews.length; i++){
            if (clickIndex == i)
                menuImageViews[i].setImageResource(menuSelectedIconResid[i]);
            else
                menuImageViews[i].setImageResource(menuIconResid[i]);
        }
    }


    public void setMenuImageViews(ImageView[] menuImageViews) {
        this.menuImageViews = menuImageViews;
    }

}
